//
//  HWLevelCell.m
//  嗨文
//
//  Created by 响当当 on 2019/2/19.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWLevelCell.h"

@interface HWLevelCell()
@property (nonatomic, strong)UIImageView *numThreeImageView;//前三
@property (nonatomic, strong)UILabel *numLabel;//后数字
@property (nonatomic, strong)UIImageView *headImageView;//头像
@property (nonatomic, strong)UILabel *nameLabel;//名字
@property (nonatomic, strong)UILabel *moneyLabel;//金额

@property (nonatomic, strong)UIView *lineView;//下划线
@end

@implementation HWLevelCell

- (UIImageView *)numThreeImageView
{
    if (!_numThreeImageView)
    {
        _numThreeImageView = [[UIImageView alloc]initWithFrame:CGRectMake(21*kUIScaleBasePlus,18*kUIScaleBasePlus,20*kUIScaleBasePlus,24*kUIScaleBasePlus)];
    }
    return _numThreeImageView;
}

- (UILabel *)numLabel
{
    if (!_numLabel)
    {
        _numLabel = [HWUtilties creatLabelWithFrame:CGRectMake(21*kUIScaleBasePlus,18*kUIScaleBasePlus,20*kUIScaleBasePlus,24*kUIScaleBasePlus)
                                       textAligment:NSTextAlignmentCenter
                                           textClor:LCHexColor(0x4B484B)
                                           textFont:18*kUIScaleBasePlus];
    }
    return _numLabel;
}

- (UIImageView *)headImageView
{
    if (!_headImageView)
    {
        _headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(58*kUIScaleBasePlus,10*kUIScaleBasePlus,40*kUIScaleBasePlus,40*kUIScaleBasePlus)];
        _headImageView.layer.masksToBounds = YES;
        _headImageView.layer.cornerRadius = _headImageView.frame.size.width/2;
    }
    return _headImageView;
}

- (UILabel *)nameLabel
{
    if (!_nameLabel)
    {
        _nameLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)+12*kUIScaleBasePlus,22*kUIScaleBasePlus,0,16*kUIScaleBasePlus)
                                         textAligment:NSTextAlignmentCenter
                                             textClor:LCHexColor(0x4B484B)
                                             textFont:16*kUIScaleBasePlus];
    }
    return _nameLabel;
}

- (UILabel *)moneyLabel
{
    if (!_moneyLabel)
    {
        _moneyLabel = [HWUtilties creatLabelWithFrame:CGRectMake(0,24*kUIScaleBasePlus,0,13*kUIScaleBasePlus)
                                         textAligment:NSTextAlignmentCenter
                                             textClor:LCHexColor(0xFC7474)
                                             textFont:14*kUIScaleBasePlus];
    }
    return _moneyLabel;
}

- (UIView *)lineView
{
    if (!_lineView)
    {
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(15*kUIScaleBasePlus,59*kUIScaleBasePlus,345*kUIScaleBasePlus,1*kUIScaleBasePlus)];
        _lineView.backgroundColor = LCHexColor(0xF5F5F5);
    }
    return _lineView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self.contentView addSubview:self.numThreeImageView];
        [self.contentView addSubview:self.numLabel];
        [self.contentView addSubview:self.headImageView];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.moneyLabel];
        [self.contentView addSubview:self.lineView];

    }
    return self;
}

#pragma mark - 获取数据
- (void)getDate:(HWLevelModel *)model andNum:(NSInteger)num;
{
    if (num == 0 || num == 1 || num == 2)
    {
        self.numThreeImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"medal_%ld",num+1]];
    }
    else
    {
        self.numThreeImageView.hidden = YES;
        self.numLabel.text = [NSString stringWithFormat:@"%ld",num+1];
        [self.numLabel sizeToFit];
    }
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.headImg]];
    
    self.nameLabel.text = model.nickName;
    [self.nameLabel sizeToFit];
    
    self.moneyLabel.text = model.profit.stringValue;
    [self.moneyLabel sizeToFit];
    [self.moneyLabel setX:SCREEN_WIDTH-self.moneyLabel.frame.size.width-35*kUIScaleBasePlus];
}

@end
